/**
 * 放置SQL 相关参数
 *
 * @author mi
 */
package com.bolt.support.sqlconfig.base;

import com.bolt.common.bean.BeanUtil;

import java.util.HashMap;
import java.util.Map;

public class DynamicContext {

    private final StringBuilder sqlBuilder = new StringBuilder();
    private Map<String, Object> bindings;
    private int uniqueNumber = 0;

    public DynamicContext(Object parameterObject) {
        this.bindings = new HashMap<>();
        if (parameterObject != null) {
            this.bindings.putAll(BeanUtil.beanToMap(parameterObject));
        }
    }

    public void appendSql(String sql) {
        sqlBuilder.append(sql);
        sqlBuilder.append(" ");
    }


    public Map<String, Object> getBindings() {
        return bindings;
    }

    public void bind(String name, Object value) {
        bindings.put(name, value);
    }


    public String getSql() {
        return sqlBuilder.toString().trim();
    }

    public int getUniqueNumber() {
        return uniqueNumber++;
    }
}
